package com.china08.yxyapi.repository.mg;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.transaction.annotation.Transactional;

import com.china08.yxyapi.entity.mg.user.YxyUserFavor;

public interface YxyUserFavorRepository extends MongoRepository<YxyUserFavor, String> {

    /**
     * 我收藏的微课
     * 
     */
    Page<YxyUserFavor> findByUserIdAndResType(String userId, String string, Pageable pageable);

    /**
     * 取消收藏
     */
    @Modifying
    @Transactional
    void deleteByResIdAndUserId(String weikeId, String userId);

    @Modifying
    @Transactional
    void deleteByResIdInAndUserIdAndUserRoleId(List<String> resId, String userId, String userRoleId);

    /**
     * 是否收藏
     */
    long countByResIdAndUserId(String id, String userId);

    /**
     * 我的收藏信息
     */
    YxyUserFavor findByResIdAndUserId(String weikeId, String userId);

    /**
     * 我收藏的微课
     */
    Page<YxyUserFavor> findByUserIdAndResTypeAndPhaseAndSubject(String userId, String string, String stage,
            String subject, Pageable pageable);

    /**
     * 我收藏的微课
     */
    Page<YxyUserFavor> findByUserIdAndResTypeAndPhaseAndSubjectAndResNameContaining(String userId, String string,
            String stage, String subject, String keyword, Pageable pageable);

    /**
     * 我收藏的微课
     */
    Page<YxyUserFavor> findByUserIdAndResTypeAndPhaseAndResNameContaining(String userId, String string, String stage,
            String keyword, Pageable pageable);

    /**
     * 我收藏的微课
     */
    Page<YxyUserFavor> findByUserIdAndResTypeAndSubjectAndResNameContaining(String userId, String string,
            String subject, String keyword, Pageable pageable);

    /**
     * 我收藏的微课
     */
    Page<YxyUserFavor> findByUserIdAndResTypeAndResNameContaining(String userId, String string, String keyword,
            Pageable pageable);

    long countByUserIdAndUserRoleIdAndResId(String userId, String id, String resId);

    /**
     * 我收藏的微课---按学段
     */
    Page<YxyUserFavor> findByUserIdAndResTypeAndPhase(String userId, String string, String stage, Pageable pageable);

    @Modifying
    @Transactional
    void deleteByResIdInAndUserId(List<String> resIds, String userId);

    Page<YxyUserFavor> findByUserIdAndSemesterIdAndResNameContaining(String userId, String semester, String keyword,
            Pageable pageableMy);

    Page<YxyUserFavor> findByUserIdAndBookContentIdInAndResNameContaining(String userId, String[] bookContent,
            String keyword, Pageable pageableMy);

    Page<YxyUserFavor> findByUserIdAndSemesterId(String userId, String semester, Pageable pageableMy);

    Page<YxyUserFavor> findByUserIdAndBookContentIdIn(String userId, String[] bookContent, Pageable pageableMy);

}
